有时,当您在公司或大学网络后面时,您可能
需要设置HTTP / HTTPS代理设置才能访问Internet。在linux上设置代理很简单,你只需要导出环境变量,就可以添加到你的shell配置文件中。
1 | export http_proxy=http://<ip>:<port> |
但是,当您尝试使用sudo运行包管理器时,这些变量将不会传递到root。当您必须使用AUR存储库并且它不会在root中构建软件包并且当您尝试使用非特权用户运行它时,这变得特别烦人,它无法通过pacman下载依赖项。有两种方法可以解决这个问题。
1) Pass on environment variables to root
- Run to following command to edit sudoers file
1 | $ sudo visudo |
- add the following line
1 | Defaults env_keep += "https_proxy http_proxy" |
这样,$ https_proxy和$ http_proxy将被sudo传递给root。
Also make sure you have set environment variables for current user. If not then you can add it by editing .bashrc if you use bash or ~/.config/fish/config.fish if you use fish like me.。
1 | export http_proxy=http://<ip>:<port> |
2) Set proxy for pacman
You also directly set proxy for pacman by editing /etc/pacman.conf
- open pacman config file by
1 | $ sudo nano nano /etc/pacman.conf |
uncomment XferCommand so that it looks like
1 | XferCommand = /usr/bin/wget --passive-ftp --proxy=on -c -O %o %u |
save it and then open /etc/wgetrc
and uncommand the following lines so that it looks like
1 | https_proxy = http://<ip>:<port> |
This should make pacman run via sudo.
For other applications like firefox you can set proxy directly through
Preferences > Advanced > Network > Settings
and for chrome / chromium you’d need to pass argument to use proxy like
1 | ~$ chromium --http-proxy=<ip>:<port> |
Most of the things which need internet and work over http/https proxy should work now.